#pragma once
#include <Windows.h>
#include <d3dx9.h>
#include <d3d9.h>
#include "Gets.h"
#include "simpleds.h"


#define GET(x,y) x Get##y(){return m_##y;}
#define SET(x,y) void Set##y(x t){ m_##y = t;}
#define GET_SET(x,y) GET(x,y) SET(x,y)

const float CAMERASPEED = 800.0f;
const D3DXVECTOR3 VECEYE = D3DXVECTOR3(800.0f,1131.37f,-800.0f);
const D3DXVECTOR3 VECAT	 = D3DXVECTOR3(0.0f,0.0f,0.0f);
const D3DXVECTOR3 VECUP	 = D3DXVECTOR3(0.0f,1.0f,0.0f);

	
class cCamera
{
public:
	typedef D3DXMATRIX MAT;
	typedef D3DXVECTOR3 VEC3;
	cCamera();
	cCamera(VEC3 _Up,VEC3 _Eye,VEC3 _At,float _Speed);
	GET(MAT,View);
	GET(MAT,Proj);
	GET(MAT,ViewProj);
	void SetView();
	void SetProj();
	void SetViewProj();
	void SetAxis();
	void NormalizeAxis();
	void XForward(float dt);
	void YForward(float dt);
	void ZForward(float dt);
	void XRotate(float angle);
	void YRotate(float angle);
	void ZRotate(float angle);
	void CameraXPos(float dt,bool isPositive);
	void CameraYPos(float dt,bool isPositive);
	void CameraZPos(float dt,bool isPositive);
	void AimXPos(float dt,bool isPositive);
	void AimYPos(float dt,bool isPositive);
	void AimZPos(float dt,bool isPositive);
	GET_SET(VEC3,XAxis);
	GET_SET(VEC3,YAxis);
	GET_SET(VEC3,ZAxis);
	GET_SET(float,Speed);
	GET_SET( VEC3, Up );
	GET_SET( VEC3, At );
	GET_SET( VEC3, Eye );

	void SetXDir(bool XForward);
	void SetYDir(bool YForward);
	void SetZDir(bool ZForward);

	void BuildFrustumPlane();
	bool CheckVisible(SPHERE& sphere);
private:
	float m_Speed;
	int m_XDir,m_YDir,m_ZDir;
	VEC3 m_Up, m_At, m_Eye;
	bool m_bXDir,m_bYDir,m_bZDir;
	
	MAT m_View;
	MAT m_Proj;
	MAT m_ViewProj;
	
	VEC3 m_XAxis,m_YAxis,m_ZAxis;
	D3DXPLANE m_FrustumPlanes[6];
};

void UpdateCamera45Fixed(float dt);
void UpdateCamera(float dt);